/**
 * 
 */
package controllers;

import client.gui.panels.ClosurePanel;
import client.gui.panels.PanelIF;
import entities.Message;
import entities.MsgType;
import entities.ObjectType;

/**
 * @author Vodi
 *
 */
public class ClosureController implements ControllerIF {

	/**
	 * reference of the controlled panel
	 */
	private ClosurePanel closurePanel;
	
	/**
	 * reference of the hosting panel's controller
	 */
	private ViewTicketController hostController; 
	
	
	public ClosureController(ViewTicketController hostController) {
		this.hostController = hostController;
	}
	
	/* (non-Javadoc)
	 * @see controllers.ControllerIF#getPanel()
	 */
	@Override
	public PanelIF getPanel() {
		return closurePanel;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#setPanel(client.gui.panels.PanelIF)
	 */
	@Override
	public void setPanel(PanelIF panel) {
		this.closurePanel = (ClosurePanel) panel;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#action()
	 */
	@Override
	public void action() {
		Long userId = closurePanel.getConnectedUserId();
		MsgType msgType;
		if(hostController.getUser().getId().equals(userId)) {
			msgType = MsgType.INITIATOR_APPROVE_CLOSE_REQUEST;
		}
		else 
			msgType = MsgType.INSPECTOR_APPROVE_CLOSE_REQUEST;
		Message message = new Message(msgType, ObjectType.LONG, userId);
		hostController.sendMessage(message);
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#decipherMessage(entities.Message)
	 */
	@Override
	public void decipherMessage(Message message) {}

}
